<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="./../template/WorkspaceTemplate.xhtml">

    <ui:define name="top">

    </ui:define>

    <ui:define name="left">

    </ui:define>

    <ui:define name="right">

    </ui:define>

    <ui:define name="content">
        <style>
            .ui-state-highlight.ui-selected {
                color: blueviolet;
            }
            .ui-commandButton-wizard-selected{
                background-color: #D20005;
                font-weight: bold;
                color: #000000;
            }
            .ui-commandButton-wizard-unselected{
                background-color: #D20005;
                font-weight: bold;
                color: #AFAFAF;
            }
        </style>
        <h2>Update Sales Order</h2>
        <h:form id="salesOrderForm" style="font-size: 85%">
            <br/>
            <p:panel >
                <p:messages  />
                <br/>
                <h:panelGrid id="panelgrid1" columns="6" cellpadding="10" style="width: 100%">
                    <h:outputLabel style="font-weight: bold" value="Client ID: "/>
                    <h:outputText id="clientId" value="#{soManagerBean.salesOrder.customer.clientId}"/>
                    <h:outputLabel value=""/>
                    <h:outputLabel value=""/>
                    <h:outputLabel style="font-weight: bold" value="Sales Order Number: "/>
                    <h:outputText value="#{soManagerBean.salesOrder.salesOrderIdStr}" />


                    <h:outputLabel style="font-weight: bold" value="Company Name: "/>
                    <h:outputText id="companyName" value="#{soManagerBean.salesOrder.customer.companyName}" />
                    <h:outputLabel value=""/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value="Purchase Order Number: "/>
                    <h:outputText value="#{soManagerBean.salesOrder.purchaseOrder.poNumber}" />

                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value="Purchase Order Date: "/>
                    <h:outputText id="quotationDate" value="#{soManagerBean.salesOrder.dateStr}"/>

                </h:panelGrid>

                <br/>
                <br/>
                <br/>

                <h:outputText value="Sales Order Status" style="font-weight: bold; font-size: 110%"/>
                <p:separator/> 
                <br/>
                <h:panelGrid columns="2" cellpadding="10">
                    <h:outputLabel style="font-weight: bold" value="Status: "/>
                    <h:outputText id="status" style="font-weight: bold; font-size: 150%; color: red" value="#{soManagerBean.salesOrder.salesOrderStatus}"/>
                </h:panelGrid>
                <br/>
                <br/>
                <br/>

                <h:outputText value="Payment Details" style="font-weight: bold; font-size: 110%"/>
                <p:separator/> 
                <br/>

                <h:panelGrid columns="2" cellpadding="10">
                    <h:outputLabel style="font-weight: bold" value="Tax Rate: "/>
                    <h:outputText value="#{soManagerBean.salesOrder.purchaseOrder.taxRate}">
                        <f:convertNumber type="percent"/>
                    </h:outputText>

                    <h:outputLabel style="font-weight: bold" value="Currency: "/>
                    <h:selectOneRadio disabled="true" value="#{soManagerBean.salesOrder.currency}">
                        <f:selectItem itemLabel="SGD" itemValue="true"/>
                        <f:selectItem itemLabel="USD" itemValue="false"/>
                    </h:selectOneRadio>

                    <h:outputLabel style="font-weight: bold" value="Payment Mode: "/>
                    <h:selectOneRadio value="#{soManagerBean.salesOrder.paymentMode}">
                        <f:selectItem itemLabel="Cash-In-Advance" itemValue="true"/>
                        <f:selectItem itemLabel="Pay-By-Credit" itemValue="false"/>
                    </h:selectOneRadio>
                </h:panelGrid>

                <br/>
                <br/>
                <br/>

                <h:outputText value="Order Items" style="font-weight: bold; font-size: 110%"/>
                <p:separator title="Order Items"/> 
                <br/>
                <p:dataTable var="oneIL" value="#{soManagerBean.salesOrder.itemLines}">
                    <p:column headerText="Product Type" rendered="#{oneIL.qtyOrderedCase != 0}">
                        <h:outputText value="#{oneIL.product.productType}"/>
                    </p:column>
                    <p:column headerText="Quantity Ordered Case" rendered="#{oneIL.qtyOrderedCase != 0}">
                        <h:outputText value="#{oneIL.qtyOrderedCase}"/>
                    </p:column>
                    <p:column headerText="Unit Price (SGD)" rendered="#{(oneIL.qtyOrderedCase != 0) &amp;&amp; (soManagerBean.salesOrder.currency)}">
                        <h:outputText value="#{oneIL.unitPriceSGD}" />
                    </p:column>
                    <p:column headerText="Unit Price (USD)" rendered="#{(oneIL.qtyOrderedCase != 0) &amp;&amp; (!soManagerBean.salesOrder.currency)}">
                        <h:outputText value="#{oneIL.unitPriceUSD}" />
                    </p:column>
                    <p:column headerText="Order Discount" rendered="#{oneIL.qtyOrderedCase != 0}">
                        <h:outputText value="#{oneIL.orderDiscount}" />
                    </p:column>
                    <p:column headerText="Special Discount" rendered="#{oneIL.qtyOrderedCase != 0}">
                        <h:outputText value="#{oneIL.specialDiscount}" />
                    </p:column>
                    <p:column headerText="Sub-total" rendered="#{oneIL.qtyOrderedCase != 0}">
                        <h:outputText value="#{oneIL.subTotal}">
                            <f:convertNumber type="currency"/>
                        </h:outputText>
                    </p:column>
                </p:dataTable>

                <br/>
                <br/>
                <br/>

                <h:outputText value="Shipping Terms" style="font-weight: bold; font-size: 110%"/>
                <p:separator title="Shipping Terms"/>
                <h:panelGrid id="panelgrid2" columns="6" cellpadding="10">
                    <h:outputLabel style="font-weight: bold" value="Freight On Board: "/>
                    <h:selectBooleanCheckbox disabled="true" id="fob" value="#{soManagerBean.salesOrder.freightOnBoard}"/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value="Shipping Details: "/>
                    <h:selectOneRadio disabled="true" id="shipment" value="#{soManagerBean.salesOrder.fullShipment}">
                        <f:selectItem itemLabel="Full Shipment" itemValue="true"/>
                        <f:selectItem itemLabel="Partial Shipment" itemValue="false"/>
                    </h:selectOneRadio>
                </h:panelGrid>

                <br/>
                <br/>
                <br/>

                <h:outputText value="Delivery Order" style="font-weight: bold; font-size: 110%"/>
                <p:separator title="Delivery Order"/> 

                <br/><br/>
                <p:fieldset legend="Delivery Order 1">  
                    <h:panelGrid columns="2" cellpadding="2" width="100%">
                        <h:outputLabel style="font-weight: bold" value="New Requested Lead Time: "/>
                        <p:calendar value="#{soManagerBean.date1}" onSelectUpdate="salesOrderForm" showOn="button" />
                        <h:outputLabel style="font-weight: bold" value="Previous Requested Lead Time: "/>
                        <h:outputText value="#{soManagerBean.do1.indicativeLeadTimeTS}">
                            <f:convertDateTime pattern="MMMM dd, yyyy"/>
                        </h:outputText>
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputLabel style="font-weight: bold" value="Shipping Address: "/>
                        <h:outputText value="#{soManagerBean.do1.shippingAddress.addressLine1}" />
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputText value="#{soManagerBean.do1.shippingAddress.addressLine2}" />
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputText value="#{soManagerBean.do1.shippingAddress.city}" />
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputText value="#{soManagerBean.do1.shippingAddress.stateName}" />
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputText value="#{soManagerBean.do1.shippingAddress.country}" />
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputText value="#{soManagerBean.do1.shippingAddress.zipCode}" />
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputLabel style="font-weight: bold" value="Confirmed Lead Time: "/>
                        <h:outputText value="#{soManagerBean.do1.leadTime}"/>
                    </h:panelGrid>
                    <br/><br/>
                    <div align="right">
                        <p:commandButton image="ui-icon ui-icon-clock" value="Get Confirmed Lead Time" actionListener="#{soManagerBean.aTPCheck1}" update="salesOrderForm"/>
                    </div>
                    <br/><br/>
                    <p:dataTable id="olilTable" var="il" value="#{soManagerBean.do1.itemLines}" emptyMessage="No products selected">  
                        <p:column rendered="#{il.qtyOrderedCase != 0}">  
                            <f:facet name="header" >  
                                Item Name
                            </f:facet>  
                            <h:outputText value="#{il.product.productType}" />  
                        </p:column>
                        <p:column rendered="#{il.qtyOrderedCase != 0}">
                            <f:facet name="header">
                                Quantity Ordered 
                                <br />
                                Case
                            </f:facet>
                            <h:outputText value="#{il.qtyOrderedCase}" />
                        </p:column>
                    </p:dataTable>
                    <br/>
                </p:fieldset>
                <br/><br/>
                <p:fieldset legend="Delivery Order 2" rendered="#{soManagerBean.do2 != null}">  
                    <h:panelGrid columns="2" cellpadding="2" style="width: 100%">
                        <h:outputLabel style="font-weight: bold" value="New Requested Lead Time: "/>
                        <p:calendar value="#{soManagerBean.date2}" onSelectUpdate="salesOrderForm" showOn="button" />
                        <h:outputLabel style="font-weight: bold" value="Previous Requested Lead Time: "/>
                        <h:outputText value="#{soManagerBean.do2.indicativeLeadTimeTS}">
                            <f:convertDateTime pattern="MMMM dd, yyyy"/>
                        </h:outputText>
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputLabel style="font-weight: bold" value="Shipping Address: "/>
                        <h:outputText value="#{soManagerBean.do2.shippingAddress.addressLine1}" />
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputText value="#{soManagerBean.do2.shippingAddress.addressLine2}" />
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputText value="#{soManagerBean.do2.shippingAddress.city}" />
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputText value="#{soManagerBean.do2.shippingAddress.stateName}" />
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputText value="#{soManagerBean.do2.shippingAddress.country}" />
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputText value="#{soManagerBean.do2.shippingAddress.zipCode}" />
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputLabel style="font-weight: bold" value=""/>
                        <h:outputLabel style="font-weight: bold" value="Confirmed Lead Time: "/>
                        <h:outputText value="#{soManagerBean.do2.leadTime}"/>
                    </h:panelGrid>
                    <br/><br/>
                    <div align="right">
                        <p:commandButton image="ui-icon ui-icon-clock" value="Get Confirmed Lead Time" actionListener="#{soManagerBean.aTPCheck2}" update="salesOrderForm"/>
                    </div>
                    <br/><br/>
                    <p:dataTable var="il" value="#{soManagerBean.do2.itemLines}" emptyMessage="No products selected">  
                        <p:column rendered="#{il.qtyOrderedCase != 0}">  
                            <f:facet name="header" >  
                                Item Name
                            </f:facet>  
                            <h:outputText value="#{il.product.productType}" />  
                        </p:column>
                        <p:column rendered="#{il.qtyOrderedCase != 0}">
                            <f:facet name="header">
                                Quantity Ordered 
                                <br />
                                Case
                            </f:facet>
                            <h:outputText value="#{il.qtyOrderedCase}" />
                        </p:column>
                    </p:dataTable>
                    <br/>
                </p:fieldset>
                <br/>

                <br/>
                <br/>
                <br/>

                <h:outputText value="Comments" style="font-weight: bold; font-size: 110%"/>
                <p:separator title="Comments"/> 
                <h:panelGrid id="panelgrid4" columns="6" cellpadding="10">
                    <h:outputText style="width:670px; height:70px;" value="#{soManagerBean.salesOrder.comments}"/><br/>
                </h:panelGrid>


                <br/>
                <br/>
                <p:separator style="height:1px; border-color: #000000; color: #000000; background-color: #000000; outline-color: #000000"/> 
                <div align="right">
                    <h3>
                        <h:panelGrid columns ="2" cellpadding="2" style="text-align: right">
                            <h:outputLabel style="font-weight: bold" value="Sub-total: "/>
                            <h:outputText value="#{soManagerBean.salesOrder.subtotal}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                            <h:outputLabel style="font-weight: bold" value="Order Discount: "/>
                            <h:outputText value="#{soManagerBean.salesOrder.orderDiscount}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                            <h:outputLabel style="font-weight: bold" value="Member Discount: "/>
                            <h:outputText value="#{soManagerBean.salesOrder.memberDiscount}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                            <h:outputLabel style="font-weight: bold" value="Special Discount: "/>
                            <h:outputText value="#{soManagerBean.salesOrder.specialDiscount}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                            <h:outputLabel style="font-weight: bold" value="Tax: "/>
                            <h:outputText value="#{soManagerBean.salesOrder.tax}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                        </h:panelGrid>
                    </h3>
                    <h2>
                        <h:panelGrid columns ="2" cellpadding="10">
                            <h:outputLabel for="total" style="font-weight: bold" value="Total: "/>
                            <h:outputText id="total" value="#{soManagerBean.salesOrder.total}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                        </h:panelGrid>
                    </h2>
                </div>

            </p:panel>

            <br/>
            <br/>
            <div align="right">
                <p:commandButton id="saveSO" value="Save Sales Order" ajax="false" action="#{soManagerBean.persistSalesOrder}" image="ui-icon ui-icon-disk" />
                <p:commandButton id="closeSO" value="Cancel Sales Order" oncomplete="confirmation.show()" image="ui-icon ui-icon-close" title="cancellation"/>
            </div>
            <br/>
            <br/>
        </h:form>

        <p:confirmDialog message="Are you sure about cancelling the sales order?" width="200"  
                         showEffect="explode" hideEffect="explode"  
                         header="Initiating cancellation" severity="alert" widgetVar="confirmation">
            <h:form id="confirmDialog">
                <p:commandButton value="Yes" update="growl" action="#{soManagerBean.cancelSalesOrder}" oncomplete="confirmation.hide()"/>  
                <p:commandButton value="No" onclick="confirmation.hide()" type="button" />
            </h:form>
        </p:confirmDialog>



    </ui:define>

    <ui:define name="bottom">

    </ui:define>

</ui:composition>